package com.example.demo.respository;

import com.example.demo.entity.domain.Teacher;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


public interface TeacherRepository extends JpaRepository<Teacher,Integer> {

    /**
     * 根据姓名模糊查询
     * @param name
     * @return
     */
    List<Teacher> findByNameLike(String name);

    /**
     * 根据学工号和密码查询
     * @param sn
     * @param password
     * @return
     */
    Teacher findBySnAndPassword(String sn,String password);


    /**
     * 根据电话和密码查询
     * @param phone
     * @param password
     * @return
     */
    Teacher findByPhoneAndPassword(String phone,String password);


    @Query(nativeQuery = true,value = "SELECT *\n" +
            "FROM teacher\n" +
            "WHERE SUBSTRING(sn, 1, 4) = (\n" +
            "    SELECT MAX(SUBSTRING(sn, 1, 4))\n" +
            "    FROM teacher\n" +
            ")\n" +
            "ORDER BY sn DESC;")
    List<Teacher> findMaxSn();


    List<Teacher> findBySn(String sn);
}
